
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/physics/quantum/operatorset.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:44 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Operator/State Helper Functions &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../../live.sympy.org/static/live-sphinx.js"></script>
    
    <link rel="shortcut icon" href="../../../_static/sympy-notailtext-favicon.ico"/>
    <link href="operatorset.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <link rel="next" title="Qapply" href="qapply.html" />
    <link rel="prev" title="Operator" href="operator.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="qapply.html" title="Qapply"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="operator.html" title="Operator"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" accesskey="U">Quantum Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Operator/State Helper Functions</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.physics.quantum.operatorset">
<span id="operator-state-helper-functions"></span><h1>Operator/State Helper Functions<a class="headerlink" href="#module-sympy.physics.quantum.operatorset" title="Permalink to this headline">¶</a></h1>
<p>A module for mapping operators to their corresponding eigenstates
and vice versa</p>
<p>It contains a global dictionary with eigenstate-operator pairings.
If a new state-operator pair is created, this dictionary should be
updated as well.</p>
<p>It also contains functions operators_to_state and state_to_operators
for mapping between the two. These can handle both classes and
instances of operators and states. See the individual function
descriptions for details.</p>
<p>TODO List:
- Update the dictionary with a complete list of state-operator pairs</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.operatorset.operators_to_state">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.operatorset.</span></span><span class="sig-name descname"><span class="pre">operators_to_state</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">operators</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/operatorset.py#L47-L145"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.operatorset.operators_to_state" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the eigenstate of the given operator or set of operators</p>
<p>A global function for mapping operator classes to their associated
states. It takes either an Operator or a set of operators and
returns the state associated with these.</p>
<p>This function can handle both instances of a given operator or
just the class itself (i.e. both XOp() and XOp)</p>
<p>There are multiple use cases to consider:</p>
<p>1) A class or set of classes is passed: First, we try to
instantiate default instances for these operators. If this fails,
then the class is simply returned. If we succeed in instantiating
default instances, then we try to call state._operators_to_state
on the operator instances. If this fails, the class is returned.
Otherwise, the instance returned by _operators_to_state is returned.</p>
<p>2) An instance or set of instances is passed: In this case,
state._operators_to_state is called on the instances passed. If
this fails, a state class is returned. If the method returns an
instance, that instance is returned.</p>
<p>In both cases, if the operator class or set does not exist in the
state_mapping dictionary, None is returned.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>arg: Operator or set</strong></p>
<blockquote>
<div><p>The class or instance of the operator or set of operators
to be mapped to a state</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.cartesian</span> <span class="kn">import</span> <span class="n">XOp</span><span class="p">,</span> <span class="n">PxOp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.operatorset</span> <span class="kn">import</span> <span class="n">operators_to_state</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.operator</span> <span class="kn">import</span> <span class="n">Operator</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">operators_to_state</span><span class="p">(</span><span class="n">XOp</span><span class="p">)</span>
<span class="go">|x&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">operators_to_state</span><span class="p">(</span><span class="n">XOp</span><span class="p">())</span>
<span class="go">|x&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">operators_to_state</span><span class="p">(</span><span class="n">PxOp</span><span class="p">)</span>
<span class="go">|px&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">operators_to_state</span><span class="p">(</span><span class="n">PxOp</span><span class="p">())</span>
<span class="go">|px&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">operators_to_state</span><span class="p">(</span><span class="n">Operator</span><span class="p">)</span>
<span class="go">|psi&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">operators_to_state</span><span class="p">(</span><span class="n">Operator</span><span class="p">())</span>
<span class="go">|psi&gt;</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.operatorset.state_to_operators">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.operatorset.</span></span><span class="sig-name descname"><span class="pre">state_to_operators</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">state</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/operatorset.py#L148-L233"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.operatorset.state_to_operators" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the operator or set of operators corresponding to the
given eigenstate</p>
<p>A global function for mapping state classes to their associated
operators or sets of operators. It takes either a state class
or instance.</p>
<p>This function can handle both instances of a given state or just
the class itself (i.e. both XKet() and XKet)</p>
<p>There are multiple use cases to consider:</p>
<p>1) A state class is passed: In this case, we first try
instantiating a default instance of the class. If this succeeds,
then we try to call state._state_to_operators on that instance.
If the creation of the default instance or if the calling of
_state_to_operators fails, then either an operator class or set of
operator classes is returned. Otherwise, the appropriate
operator instances are returned.</p>
<p>2) A state instance is returned: Here, state._state_to_operators
is called for the instance. If this fails, then a class or set of
operator classes is returned. Otherwise, the instances are returned.</p>
<p>In either case, if the state’s class does not exist in
state_mapping, None is returned.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>arg: StateBase class or instance (or subclasses)</strong></p>
<blockquote>
<div><p>The class or instance of the state to be mapped to an
operator or set of operators</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.cartesian</span> <span class="kn">import</span> <span class="n">XKet</span><span class="p">,</span> <span class="n">PxKet</span><span class="p">,</span> <span class="n">XBra</span><span class="p">,</span> <span class="n">PxBra</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.operatorset</span> <span class="kn">import</span> <span class="n">state_to_operators</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.quantum.state</span> <span class="kn">import</span> <span class="n">Ket</span><span class="p">,</span> <span class="n">Bra</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">state_to_operators</span><span class="p">(</span><span class="n">XKet</span><span class="p">)</span>
<span class="go">X</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">state_to_operators</span><span class="p">(</span><span class="n">XKet</span><span class="p">())</span>
<span class="go">X</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">state_to_operators</span><span class="p">(</span><span class="n">PxKet</span><span class="p">)</span>
<span class="go">Px</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">state_to_operators</span><span class="p">(</span><span class="n">PxKet</span><span class="p">())</span>
<span class="go">Px</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">state_to_operators</span><span class="p">(</span><span class="n">PxBra</span><span class="p">)</span>
<span class="go">Px</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">state_to_operators</span><span class="p">(</span><span class="n">XBra</span><span class="p">)</span>
<span class="go">X</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">state_to_operators</span><span class="p">(</span><span class="n">Ket</span><span class="p">)</span>
<span class="go">O</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">state_to_operators</span><span class="p">(</span><span class="n">Bra</span><span class="p">)</span>
<span class="go">O</span>
</pre></div>
</div>
</dd></dl>

</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="operator.html"
                        title="previous chapter">Operator</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="qapply.html"
                        title="next chapter">Qapply</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/modules/physics/quantum/operatorset.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="qapply.html" title="Qapply"
             >next</a> |</li>
        <li class="right" >
          <a href="operator.html" title="Operator"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" >Quantum Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Operator/State Helper Functions</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/physics/quantum/operatorset.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:45 GMT -->
</html>